import logo from '@/assets/icons/ai-logo-eai.svg';
import aiaaImg from '@/assets/images/background/aiaa.png';
import entImg from '@/assets/images/background/ent.svg';
import homepage from '@/assets/images/background/homepagebg.svg';
import medImg from '@/assets/images/background/med.svg';
import { CreateUser } from '@/common';
import { MongoImageTypeEnum, OutLinkChatAuthProps } from '@/pages/chat/tools/constants';
import { AppDetailType } from '@/types/app/type';

export interface AppListReq {
  page: number;
  page_size: number;
  type?: string;
  name?: string;
}

export interface AppListRes {
  list: AppListItem[];
  total: number;
  page: number;
  page_size: number;
}

export interface TemplateApp {
  id: string;
  name: string;
}

export interface AppListItem {
  id: string;
  name: string;
  avatar: string;
  status: string;
  industry: string;
  background_image_url: string;
  description: string;
  dataset: AppDataset;
  metahuman: AppMetahuman;
  share_id: string;
  welcome_text?: string;
  create_time: string;
  update_time: string;
  template_app?: TemplateApp;
}

export interface AppDataset {
  id: string;
  name: string;
}

export interface AppMetahuman {
  id: string;
  name: string;
  preview_url: string;
  avatar_id: string;
}

export interface CreateAppReq {
  template_app_id: string;
  name: string;
  metahuman_id: string;
}

export interface UpdateAppReq {
  name?: string;
  background_image_url?: string;
  description?: string;
  metahumanId?: string;
  avatar?: string;
  metahuman?: AppMetahuman;
}

export type preUploadImgProps = OutLinkChatAuthProps & {
  type: `${MongoImageTypeEnum}`;

  expiredTime?: Date;
  metadata?: Record<string, any>;
};

export type UploadImageReq = preUploadImgProps & {
  base64Img: string;
  image_func_type: 'scene' | 'logo';
  file: File;
};

export interface FcsUploadImageReq {
  file_name?: string;
  file: File;
}

export interface SurveyContent {
  title: string;
  score: number;
  feedback: string;
}

export interface UpdateSurveyReq {
  // code: string
  content: SurveyContent;
}

export interface hotIssues {
  enable: boolean;
  order: number;
  content: string;
}

export interface agentSquareType {
  appId: string;
  appName: string;
  avatar: string;
  shareId: string;
}
export interface historicalDialogueType {
  highlight_content: string;
  id: string;
  obj: string;
  time: string;
  title: string;
  userId: string;
  _id: string;
  appId: string;
  shareId: string;
}

export type IndustryType =
  | 'aiaa'
  | 'edu'
  | 'med'
  | 'ent'
  | 'default'
  | 'agentLogo2'
  | 'agentLogo3'
  | 'workflowLogo1'
  | 'workflowLogo2'
  | 'workflowLogo3'
  | 'fusionLogo1'
  | 'fusionLogo2'
  | 'fusionLogo3';

export type MenuContentType =
  | 'collect-chat-type'
  | 'search'
  | 'chat'
  | 'history'
  | 'history-chat'
  | 'collect-chat'
  | 'public-agent'
  | 'homepage'
  | 'dashboard'
  | null;

export interface UpdateBrandingInfo {
  display_name?: string;
  logo?: string;
  subtitle?: string;
  home_text?: string;
  management_text?: string;
  welcome_text?: string;
  hot_subtitle?: string;
  hot_issues: hotIssues[];
  release_time?: string;
  industry_type?: IndustryType;
}

const imageMap: Record<IndustryType, string> = {
  aiaa: aiaaImg,
  edu: homepage,
  med: medImg,
  ent: entImg,
  default: logo,
};

const industryOptions: { label: string; value: IndustryType }[] = [
  { label: '招生助手', value: 'aiaa' },
  { label: '高校', value: 'edu' },
  { label: '医疗', value: 'med' },
  { label: '企业', value: 'ent' },
];

export { imageMap, industryOptions };

export interface ExtensionInfo {
  id?: string;
  name: string;
  web_url?: string;
  app_url?: string;
  category: string;
  system: string;
  description: string;
  app_id?: string;
}

export interface ExtensionpageData {
  category?: string;
  keywords?: string;
  page_size?: number;
  page?: number;
  app_id?: string;
}

export interface InitializeData {
  app?: InitializeDataApp;
  debug?: boolean;
  enable_role_conditions?: boolean;
  enable_knowledge_governance?: boolean;
  enable_permission_share?: boolean;
  max_supported_file_count?: number;
  max_supported_single_file_size?: number;
  login_page_display?: boolean;
  work_permissions: [];
  is_knowledge_manager?: boolean;
  is_knowledge_reviewer?: boolean;
  preview_file_types?: string;
  use_legacy_version?: boolean;
  allowLocalAccount?: boolean;
  enableMetahuman?: boolean;
}

export interface MessageDataType {
  action_time: string;
  detail: string;
  message: string;
  meta_data: {};
  module: string;
  next_actions: { display_text: string; forward_to: string };
  notification_id: string;
  status: string;
  user_info: {
    user_id: string;
    user_name: string;
  };
}

export interface InitializeDataApp {
  debug?: boolean;
  id?: string;
  share_id?: string;
}

export enum BrandingEnum {
  display_name = '校园百事通',
  home_text = '我是您的校园顾问，想了解学校的信息就快来问我吧，为您提供优质全面的回答',
  management_text = '开启您的校园智能管理，为您智能化管理校园，为您提供优质全面的回答',
  welcome_text = '您好，我是您的校园百事通，欢迎向我提问！',
  permission_manage = 'permission-manage',
  app_orchestration = 'orchestration',
}

export enum LicenseEditionEnum {
  basic = 'BASE',
  standard = 'STANDARD',
  custom = 'ENTERPRISE',
}

export enum LicenseEditionNameEnum {
  BASE = '基础版',
  STANDARD = '标准版',
  ENTERPRISE = '定制版',
}
export enum AppTypeNumEnum {
  MANAGER = 6,
  PUBLIC = 3,
  MARKET = 3,
}

export interface CreateAppV2Req {
  app_type?: string;
  template_app_id?: string;
  app_name?: string;
  tag?: string;
  app_description?: string;
  app_logo?: string;
  scene_image?: string;
}

export interface AppChatConfig {
  roleSetup: string;
  task: string;
  openingRemarks: string;
  answerTone: string;
  answerStrictness: string;
  deepThink: boolean;
  voiceEnabled: boolean;
  guessYouWant2ask: boolean;
  hotIssues: boolean;
  inputGuide: boolean;
}

export interface AppBasicInfo {
  appDescription: string;
  appLogo: string;
  sceneImage: string;
}

export interface ConfigurationsInfo {
  name: string;
  tag: string;
  type?: string;
  description?: string;
  default_value: string | number | boolean;
  max_length?: number;
  max_value?: number;
  min_value?: number;
  list_value?: string[];
}

export interface CreateAppV2Res {
  app_id: string;
  share_id: string;
  basic_info: AppBasicInfo;
  chat_config: AppChatConfig;
  configurations: ConfigurationsInfo[];
}

export interface FlowNodePosition {
  x: number;
  y: number;
}

export interface FlowNodeInput {
  [key: string]: any;
}

export interface FlowNode {
  nodeId: string;
  name: string;
  intro: string;
  avatar: string;
  flowNodeType: string;
  showStatus: boolean;
  position: FlowNodePosition;
  version: string;
  inputs: FlowNodeInput[];
  outputs: any[];
}

export interface AppWorkFlow {
  parent_id: string;
  avatar: string;
  name: string;
  type: string;
  modules: FlowNode[];
  edges: string[];
}

export interface AppKnowledge {
  files: string[];
  apis: string[];
  apps: string[];
}

export interface UpdateAppV2Req {
  app_id: string;
  share_id: string;
  app_logo?: string;
  app_name?: string;
  app_description?: string;
  scene_image?: string;
  configurations: ConfigurationsInfo[];
  workflow?: AppDetailType;
  roles_for_user_in_app?: string[];
  permission_config?: PermissionConfigItem[];
  variables?: Record<string, any>[];
  appType: string;
  review_status: string;
}

export interface UpdateAppV2Res {
  app_id: string;
}

/// 权限配置目标
export interface PermissionConfigTarget {
  target_id: string;
  target_type: string;
  target_name: string;
}

/// 权限配置资源
export interface PermissionConfigResource {
  resource_type: string;
  resource_id: string;
  action: string;
}

/// 权限配置项
export interface PermissionConfigItem {
  target: PermissionConfigTarget;
  resources: PermissionConfigResource[];
}

export interface PublishAppV2Req {
  is_publish: boolean;
  version_name?: string;
  is_all_can_qa?: boolean;
  configurations: ConfigurationsInfo[];
  permission_config: PermissionConfigItem[];
}

export interface PublishAppV2Res {
  app_id: string;
}

export interface AppReviewHistoryReq {
  page: number;
  page_size: number;
}

export interface AppReviewItem {
  review_result: 'pass' | 'reject';
  review_description: string;
}

export interface GetReviewAppListReq {
  page: number;
  page_size: number;
  searchText?: string;
}

export interface GetReviewAppList {
  app_id: string;
  name: string;
  app_type: string;
  app_description: string;
  user_name: string;
  group_name: string;
  create_time: string;
  review_time: string;
  review_result: 'pass' | 'reject';
  review_description: string;
  is_visible: boolean;
}

export interface GetWorkBenhList {
  app_id: string;
  appId?: string;
  name?: string;
  description?: string;
  toolName?: string;
  app_name: string;
  app_type: string;
  app_description: string;
  user_name: string;
  group_name: string;
  create_time: string;
  review_time: string;
  review_result: 'pass' | 'reject';
  review_description: string;
  app_logo: string;
  scene_image?: string;
  configurations: ConfigurationsInfo[];
  workflow?: AppDetailType;
  roles_for_user_in_app?: string[];
  permission_config?: PermissionConfigItem[];
  review_status: string;
  app_template_type: string;
  app_workbench_type: string;
  templateUsageCount: number;
  templateThumbUpCount: number;
  templateThumbDownCount: number;
  isCollect: boolean;
  checked?: boolean;
  share_id: string;
  createUser: CreateUser;
}

export interface AppReviewHistoryRes {
  total: number;
  app_review_list: AppReviewItem[];
}

export interface HotIssue {
  content: string;
  answer: string;
}

export interface HotIssueRes {
  hot_issues: HotIssue[];
}

export interface UpdateHotIssueReq {
  hot_issues: HotIssue[];
}

export interface UpdateInputGuideReq {
  input_guide: string[];
}

export interface InputGuideRes {
  input_guide: string[];
}

export interface GetImageRes {
  logo: string[];
  scene: string[];
}

export interface AppReviewReq {
  review_result: 'pass' | 'reject';
  review_description: string;
}

export interface AppReviewRes {
  reviewer: string;
  update_time: string;
  review_description: string;
}

export interface AppPublishHistoryRes {
  version_list: AppPublishHistory[];
}

export interface AppPublishHistory {
  id: string;
  name: string;
  time: string;
}

export interface GetReviewAppListRes {
  list: GetReviewAppList[];
  total: number;
}

export interface ReviewAppReq {
  review_result: 'pass' | 'reject';
  review_description?: string;
}

export interface ReviewAppRes {
  review_description: null | string;
  reviewer: string;
  update_time: null | string;
}

export interface ApprovedList {
  app_id?: string;
  name?: string;
  create_user_id: string;
  avatar: string;
  enable_application_recommend: boolean;
  enable_function_calling: boolean;
  disable_dataset: boolean;
}

export interface ApprovedRes {
  list: ApprovedList[];
}
export interface ApprovedReq {
  needPagination: boolean;
  page: number;
  page_size: number;
  searchText: string;
  appType?: string;
}

export interface UpdateAppImageReq {
  logo: string[];
  scene: string[];
}
export interface GetTestListType {
  id: string;
  name: string;
  accuracy: number;
  appId: string;
  creatorName: string;
  endTime: string;
  exeFile: string;
  message: string;
  progress: number;
  startTime: string;
  status: number;
}

export interface ListDeleteReq {
  taskIds: string[];
}

export enum StatusType {
  SUCCESS = 'SUCCESS', // 已完成
  PROCESSING = 'PROCESSING', // 进行中
  QUEUE = 'QUEUE', // 排队中
  FAIL = 'FAIL', // 错误
}
